﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace AgvSystem.Web.User_Info
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int Id=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(Id);
				}
			}
		}
			
	private void ShowInfo(int Id)
	{
		AgvSystem.BLL.User_Info bll=new AgvSystem.BLL.User_Info();
		AgvSystem.Model.User_Info model=bll.GetModel(Id);
		this.lblId.Text=model.Id.ToString();
		this.txtUser_Account.Text=model.User_Account;
		this.txtUser_Password.Text=model.User_Password;
		this.txtRole.Text=model.Role.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtUser_Account.Text.Trim().Length==0)
			{
				strErr+="User_Account不能为空！\\n";	
			}
			if(this.txtUser_Password.Text.Trim().Length==0)
			{
				strErr+="User_Password不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtRole.Text))
			{
				strErr+="Role格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int Id=int.Parse(this.lblId.Text);
			string User_Account=this.txtUser_Account.Text;
			string User_Password=this.txtUser_Password.Text;
			int Role=int.Parse(this.txtRole.Text);


			AgvSystem.Model.User_Info model=new AgvSystem.Model.User_Info();
			model.Id=Id;
			model.User_Account=User_Account;
			model.User_Password=User_Password;
			model.Role=Role;

			AgvSystem.BLL.User_Info bll=new AgvSystem.BLL.User_Info();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
